/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.agtranscontinental.sisref.model;

import com.agtranscontinental.sisref.dto.FotoDto;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 *
 * @author ericson
 */
@Entity
@Table(name = "foto")
@NamedQueries({
    @NamedQuery(name = "Foto.findAll", query = "SELECT f FROM Foto f"),
    @NamedQuery(name = "Foto.findById", query = "SELECT f FROM Foto f WHERE f.id = :id"),
    @NamedQuery(name = "Foto.findByNbre", query = "SELECT f FROM Foto f WHERE f.nbre = :nbre"),
    @NamedQuery(name = "Foto.findByDccion", query = "SELECT f FROM Foto f WHERE f.dccion = :dccion")})
public class Foto implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;
    @Size(max = 80)
    @Column(name = "nbre")
    private String nbre;
    @Size(max = 150)
    @Column(name = "dccion")
    private String dccion;
    @JoinColumn(name = "id_rvsion", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private Revision revision;

    public Foto() {
    }

    public Foto(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getNbre() {
        return nbre;
    }

    public void setNbre(String nbre) {
        this.nbre = nbre;
    }

    public String getDccion() {
        return dccion;
    }

    public void setDccion(String dccion) {
        this.dccion = dccion;
    }

    public Revision getRevision() {
        return revision;
    }

    public void setRevision(Revision revision) {
        this.revision = revision;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Foto)) {
            return false;
        }
        Foto other = (Foto) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.agtranconstinental.sisref.Foto[ id=" + id + " ]";
    }

    public static final Foto parseToFoto(FotoDto fotoDto) {
        if (fotoDto != null) {
            Foto foto = new Foto();
            foto.setId(fotoDto.getId());
            foto.setDccion(fotoDto.getDccion());
            foto.setNbre(fotoDto.getNmbre());
            Revision revision = new Revision();
            revision.setId(fotoDto.getIdRvsion());
            foto.setRevision(revision);
            return foto;
        }
        return null;
    }

}
